
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Using combineReducers · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="BeyondCombineReducers.html" />
    
    
    <link rel="prev" href="RefactoringReducersExample.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Read Me
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../introduction/">
            
                <a href="../../introduction/">
            
                    
                    Introduction
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../introduction/Motivation.html">
            
                <a href="../../introduction/Motivation.html">
            
                    
                    Motivation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../../introduction/CoreConcepts.html">
            
                <a href="../../introduction/CoreConcepts.html">
            
                    
                    Core Concepts
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../../introduction/ThreePrinciples.html">
            
                <a href="../../introduction/ThreePrinciples.html">
            
                    
                    Three Principles
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../../introduction/PriorArt.html">
            
                <a href="../../introduction/PriorArt.html">
            
                    
                    Prior Art
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../../introduction/Ecosystem.html">
            
                <a href="../../introduction/Ecosystem.html">
            
                    
                    Ecosystem
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../../introduction/Examples.html">
            
                <a href="../../introduction/Examples.html">
            
                    
                    Examples
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../basics/">
            
                <a href="../../basics/">
            
                    
                    Basics
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../basics/Actions.html">
            
                <a href="../../basics/Actions.html">
            
                    
                    Actions
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../../basics/Reducers.html">
            
                <a href="../../basics/Reducers.html">
            
                    
                    Reducers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../../basics/Store.html">
            
                <a href="../../basics/Store.html">
            
                    
                    Store
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../../basics/DataFlow.html">
            
                <a href="../../basics/DataFlow.html">
            
                    
                    Data Flow
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../../basics/UsageWithReact.html">
            
                <a href="../../basics/UsageWithReact.html">
            
                    
                    Usage with React
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../../basics/ExampleTodoList.html">
            
                <a href="../../basics/ExampleTodoList.html">
            
                    
                    Example: Todo List
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../../advanced/">
            
                <a href="../../advanced/">
            
                    
                    Advanced
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../../advanced/AsyncActions.html">
            
                <a href="../../advanced/AsyncActions.html">
            
                    
                    Async Actions
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../../advanced/AsyncFlow.html">
            
                <a href="../../advanced/AsyncFlow.html">
            
                    
                    Async Flow
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../../advanced/Middleware.html">
            
                <a href="../../advanced/Middleware.html">
            
                    
                    Middleware
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../../advanced/UsageWithReactRouter.html">
            
                <a href="../../advanced/UsageWithReactRouter.html">
            
                    
                    Usage with React Router
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../../advanced/ExampleRedditAPI.html">
            
                <a href="../../advanced/ExampleRedditAPI.html">
            
                    
                    Example: Reddit API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" >
            
                <span>
            
                    
                    Next Steps
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../">
            
                <a href="../">
            
                    
                    Recipes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../MigratingToRedux.html">
            
                <a href="../MigratingToRedux.html">
            
                    
                    Migrating to Redux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../UsingObjectSpreadOperator.html">
            
                <a href="../UsingObjectSpreadOperator.html">
            
                    
                    Using Object Spread Operator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../ReducingBoilerplate.html">
            
                <a href="../ReducingBoilerplate.html">
            
                    
                    Reducing Boilerplate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../ServerRendering.html">
            
                <a href="../ServerRendering.html">
            
                    
                    Server Rendering
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../WritingTests.html">
            
                <a href="../WritingTests.html">
            
                    
                    Writing Tests
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../ComputingDerivedData.html">
            
                <a href="../ComputingDerivedData.html">
            
                    
                    Computing Derived Data
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="../ImplementingUndoHistory.html">
            
                <a href="../ImplementingUndoHistory.html">
            
                    
                    Implementing Undo History
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="../IsolatingSubapps.html">
            
                <a href="../IsolatingSubapps.html">
            
                    
                    Isolating Subapps
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="../StructuringReducers.html">
            
                <a href="../StructuringReducers.html">
            
                    
                    Structuring Reducers
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.9.1" data-path="PrerequisiteConcepts.html">
            
                <a href="PrerequisiteConcepts.html">
            
                    
                    Prerequisite Concepts
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9.2" data-path="BasicReducerStructure.html">
            
                <a href="BasicReducerStructure.html">
            
                    
                    Basic Reducer Structure
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9.3" data-path="SplittingReducerLogic.html">
            
                <a href="SplittingReducerLogic.html">
            
                    
                    Splitting Reducer Logic
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9.4" data-path="RefactoringReducersExample.html">
            
                <a href="RefactoringReducersExample.html">
            
                    
                    Refactoring Reducers Example
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.9.5" data-path="UsingCombineReducers.html">
            
                <a href="UsingCombineReducers.html">
            
                    
                    Using combineReducers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9.6" data-path="BeyondCombineReducers.html">
            
                <a href="BeyondCombineReducers.html">
            
                    
                    Beyond combineReducers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9.7" data-path="NormalizingStateShape.html">
            
                <a href="NormalizingStateShape.html">
            
                    
                    Normalizing State Shape
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9.8" data-path="UpdatingNormalizedData.html">
            
                <a href="UpdatingNormalizedData.html">
            
                    
                    Updating Normalized Data
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9.9" data-path="ReusingReducerLogic.html">
            
                <a href="ReusingReducerLogic.html">
            
                    
                    Reusing Reducer Logic
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9.10" data-path="ImmutableUpdatePatterns.html">
            
                <a href="ImmutableUpdatePatterns.html">
            
                    
                    Immutable Update Patterns
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9.11" data-path="InitializingState.html">
            
                <a href="InitializingState.html">
            
                    
                    Initializing State
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5.10" data-path="../UsingImmutableJS.html">
            
                <a href="../UsingImmutableJS.html">
            
                    
                    Using Immutable.JS with Redux
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../../FAQ.html">
            
                <a href="../../FAQ.html">
            
                    
                    FAQ
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../../faq/General.html">
            
                <a href="../../faq/General.html">
            
                    
                    General
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../../faq/Reducers.html">
            
                <a href="../../faq/Reducers.html">
            
                    
                    Reducers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../../faq/OrganizingState.html">
            
                <a href="../../faq/OrganizingState.html">
            
                    
                    Organizing State
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../../faq/StoreSetup.html">
            
                <a href="../../faq/StoreSetup.html">
            
                    
                    Store Setup
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../../faq/Actions.html">
            
                <a href="../../faq/Actions.html">
            
                    
                    Actions
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../../faq/ImmutableData.html">
            
                <a href="../../faq/ImmutableData.html">
            
                    
                    Immutable Data
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../../faq/CodeStructure.html">
            
                <a href="../../faq/CodeStructure.html">
            
                    
                    Code Structure
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../../faq/Performance.html">
            
                <a href="../../faq/Performance.html">
            
                    
                    Performance
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../../faq/ReactRedux.html">
            
                <a href="../../faq/ReactRedux.html">
            
                    
                    React Redux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../../faq/Miscellaneous.html">
            
                <a href="../../faq/Miscellaneous.html">
            
                    
                    Miscellaneous
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../../Troubleshooting.html">
            
                <a href="../../Troubleshooting.html">
            
                    
                    Troubleshooting
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../../Glossary.html">
            
                <a href="../../Glossary.html">
            
                    
                    Glossary
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../../api/">
            
                <a href="../../api/">
            
                    
                    API Reference
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../../api/createStore.html">
            
                <a href="../../api/createStore.html">
            
                    
                    createStore
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../../api/Store.html">
            
                <a href="../../api/Store.html">
            
                    
                    Store
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../../api/combineReducers.html">
            
                <a href="../../api/combineReducers.html">
            
                    
                    combineReducers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../../api/applyMiddleware.html">
            
                <a href="../../api/applyMiddleware.html">
            
                    
                    applyMiddleware
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../../api/bindActionCreators.html">
            
                <a href="../../api/bindActionCreators.html">
            
                    
                    bindActionCreators
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.6" data-path="../../api/compose.html">
            
                <a href="../../api/compose.html">
            
                    
                    compose
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../../CHANGELOG.md">
            
                <span>
            
                    
                    Change Log
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../../PATRONS.md">
            
                <span>
            
                    
                    Patrons
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../../Feedback.html">
            
                <a href="../../Feedback.html">
            
                    
                    Feedback
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Using combineReducers</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="using-combinereducers">Using <code>combineReducers</code></h1>
<h2 id="core-concepts">Core Concepts</h2>
<p>The most common <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> shape for a Redux app is a plain Javascript object containing &quot;slices&quot; of domain-specific data at each top-level key.  Similarly, the most common approach to writing <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a> logic for that <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> shape is to have &quot;slice <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a>&quot; functions, each with the same <code>(state, action)</code> signature, and each responsible for managing all updates to that specific slice of <a href="../../Glossary.html#state" class="glossary-term" title="">state</a>.  Multiple slice reducers can respond to the same <a href="../../Glossary.html#action" class="glossary-term" title="">action</a>, independently update their own slice as needed, and the updated slices are combined into the new <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> object.</p>
<p>Because this pattern is so common, Redux provides the <code>combineReducers</code> utility to implement that behavior.  It is an example of a <em>higher-order <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a></em>, which takes an object full of slice <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a> functions, and returns a new <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a> function.</p>
<p>There are several important ideas to be aware of when using <code>combineReducers</code>:</p>
<ul>
<li>First and foremost, <code>combineReducers</code> is simply <strong>a utility function to simplify the most common use case when writing Redux reducers</strong>.  You are <em>not</em> required to use it in your own application, and it does <em>not</em> handle every possible scenario.  It is entirely possible to write <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a> logic without using it, and it is quite common to need to write custom <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a> logic for cases that <code>combineReducer</code> does not handle.  (See <a href="BeyondCombineReducers.html">Beyond <code>combineReducers</code></a> for examples and suggestions.)  </li>
<li>While Redux itself is not opinionated about how your <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> is organized, <code>combineReducers</code> enforces several rules to help users avoid common errors.  (See <a href="../../api/combineReducers.html"><code>combineReducers</code></a> for details.)</li>
<li>One frequently asked question is whether Redux &quot;calls all reducers&quot; when dispatching an <a href="../../Glossary.html#action" class="glossary-term" title="">action</a>.  Since there really is only one root <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a> function, the default answer is &quot;no, it does not&quot;.  However, <code>combineReducers</code> has specific behavior that <em>does</em> work that way.  In order to assemble the new <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> tree, <code>combineReducers</code> will call each slice <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a> with its current slice of <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> and the current <a href="../../Glossary.html#action" class="glossary-term" title="">action</a>, giving the slice <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a> a chance to respond and update its slice of <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> if needed.  So, in that sense, using <code>combineReducers</code> <em>does</em> &quot;call all reducers&quot;, or at least all of the slice reducers it is wrapping.</li>
<li>You can use it at all levels of your <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a> structure, not just to create the root <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a>.  It&apos;s very common to have multiple combined reducers in various places, which are composed together to create the root <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a>.</li>
</ul>
<h2 id="defining-state-shape">Defining State Shape</h2>
<p>There are two ways to define the initial shape and contents of your <a href="../../Glossary.html#store" class="glossary-term" title="">store</a>&apos;s <a href="../../Glossary.html#state" class="glossary-term" title="">state</a>.  First, the <code>createStore</code> function can take <code>preloadedState</code> as its second argument.  This is primarily intended for initializing the <a href="../../Glossary.html#store" class="glossary-term" title="">store</a> with <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> that was previously persisted elsewhere, such as the browser&apos;s localStorage.  The other way is for the root <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a> to return the initial <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> value when the <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> argument is <code>undefined</code>.  These two approaches are described in more detail in <a href="InitializingState.html">Initializing State</a>, but there are some additional concerns to be aware of when using <code>combineReducers</code>.</p>
<p><code>combineReducers</code> takes an object full of slice <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a> functions, and creates a function that outputs a corresponding <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> object with the same keys.  This means that if no preloaded <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> is provided to <code>createStore</code>, the naming of the keys in the input slice <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a> object will define the naming of the keys in the output <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> object.  The correlation between these names is not always apparent, especially when using ES6 features such as default module exports and object literal shorthands.</p>
<p>Here&apos;s an example of how use of ES6 object literal shorthand with <code>combineReducers</code> can define the <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> shape:</p>
<pre><code class="lang-js"><span class="hljs-comment">// reducers.js</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> theDefaultReducer = (state = <span class="hljs-number">0</span>, action) =&gt; state;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> firstNamedReducer = (state = <span class="hljs-number">1</span>, action) =&gt; state;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> secondNamedReducer = (state = <span class="hljs-number">2</span>, action) =&gt; state;


<span class="hljs-comment">// rootReducer.js</span>
<span class="hljs-keyword">import</span> {combineReducers, createStore} <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;redux&quot;</span>;

<span class="hljs-keyword">import</span> theDefaultReducer, {firstNamedReducer, secondNamedReducer} <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;./reducers&quot;</span>;

<span class="hljs-comment">// Use ES6 object literal shorthand syntax to define the object shape</span>
<span class="hljs-keyword">const</span> rootReducer = combineReducers({
    theDefaultReducer,
    firstNamedReducer,
    secondNamedReducer
});

<span class="hljs-keyword">const</span> store = createStore(rootReducer);
<span class="hljs-built_in">console</span>.log(store.getState());
<span class="hljs-comment">// {theDefaultReducer : 0, firstNamedReducer : 1, secondNamedReducer : 2}</span>
</code></pre>
<p>Notice that because we used the ES6 shorthand for defining an object literal, the key names in the resulting <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> are the same as the variable names from the imports.  This may not always be the desired behavior, and is often a cause of confusion for those who aren&apos;t as familiar with ES6 syntax.</p>
<p>Also, the resulting names are a bit odd.  It&apos;s generally not a good practice to actually include words like &quot;<a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a>&quot; in your <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> key names - the keys should simply reflect the domain or type of data they hold.  This means we should either explicitly specify the names of the keys in the slice <a href="../../Glossary.html#reducer" class="glossary-term" title="">reducer</a> object to define the keys in the output <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> object, or carefully rename the variables for the imported slice reducers to set up the keys when using the shorthand object literal syntax.</p>
<p>A better usage might look like:</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> {combineReducers, createStore} <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;redux&quot;</span>;

<span class="hljs-comment">// Rename the default import to whatever name we want. We can also rename a named import.</span>
<span class="hljs-keyword">import</span> defaultState, {firstNamedReducer, secondNamedReducer <span class="hljs-keyword">as</span> secondState} <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;./reducers&quot;</span>;

<span class="hljs-keyword">const</span> rootReducer = combineReducers({
    defaultState,                   <span class="hljs-comment">// key name same as the carefully renamed default export</span>
    firstState : firstNamedReducer, <span class="hljs-comment">// specific key name instead of the variable name</span>
    secondState,                    <span class="hljs-comment">// key name same as the carefully renamed named export</span>
});

<span class="hljs-keyword">const</span> reducerInitializedStore = createStore(rootReducer);
<span class="hljs-built_in">console</span>.log(reducerInitializedStore.getState());
<span class="hljs-comment">// {defaultState : 0, firstState : 1, secondState : 2}</span>
</code></pre>
<p>This <a href="../../Glossary.html#state" class="glossary-term" title="">state</a> shape better reflects the data involved, because we took care to set up the keys we passed to <code>combineReducers</code>.</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="RefactoringReducersExample.html" class="navigation navigation-prev " aria-label="Previous page: Refactoring Reducers Example">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="BeyondCombineReducers.html" class="navigation navigation-next " aria-label="Next page: Beyond combineReducers">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Using combineReducers","level":"1.5.9.5","depth":3,"next":{"title":"Beyond combineReducers","level":"1.5.9.6","depth":3,"path":"recipes/reducers/BeyondCombineReducers.md","ref":"./recipes/reducers/BeyondCombineReducers.md","articles":[]},"previous":{"title":"Refactoring Reducers Example","level":"1.5.9.4","depth":3,"path":"recipes/reducers/RefactoringReducersExample.md","ref":"./recipes/reducers/RefactoringReducersExample.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"recipes/reducers/UsingCombineReducers.md","mtime":"2017-03-13T14:28:11.366Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-03-15T14:47:19.389Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

